package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.CourseBaseDto;
import com.xuecheng.commons.model.dto.CourseDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.CourseAuditDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.content.domain.CourseBase;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 课程基本信息前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/course")
public class CourseBaseController {

    @Autowired
    private CourseBaseService  courseBaseService;

    @PostMapping("/list")
    public ResponseResult list(PageRequest request, @RequestBody CourseDto dto){
return courseBaseService.courseList(request,dto);
    }


    @PostMapping("/upload")
    public ResponseResult upload(MultipartFile uploadFile)throws Exception{
return courseBaseService.upload(uploadFile);
    }

//保存
    @PostMapping
    public ResponseResult saveCourseBase(@RequestBody CourseBaseDto dto){
        return courseBaseService.saveCourseBase(dto);
    }

    //修改
    @PutMapping
    public ResponseResult updateCourseBase(@RequestBody CourseBaseDto dto){
        return courseBaseService.updateCourseBase(dto);
    }

//    //删除
//    @DeleteMapping
//    public ResponseResult delete(CourseBaseDto dto){
//return courseBaseService.delete();
//    }
//根据Id查询
@GetMapping("/{courseBaseId}")
public ResponseResult findById(@PathVariable("courseBaseId")Long courseBaseId){
//根据ID查询
    CourseBase courseBase = courseBaseService.getById(courseBaseId);
    //将courseBaseId对象转化成vo
    CourseBase vo = BeanHelper.copyProperties(courseBase, CourseBase.class);
    return ResponseResult.okResult(vo);

}
//修改课程
    @PutMapping
    public ResponseResult update(@RequestBody CourseBaseDto dto){
        return courseBaseService.updateCourse(dto);
    }
    @GetMapping("/commit/{couaseBaseId}")
    public ResponseResult commit(@PathVariable("courseBaseId")Long courseBaseId){
return courseBaseService.commit(courseBaseId);
    }
    @PostMapping("/approve")
    public ResponseResult approve(@RequestBody CourseAuditDto dto){
return courseBaseService.approve(dto);
    }
}
